package com.nmf.pc.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.nmf.pc.enums.RspStatus;
import com.nmf.pc.vo.ReturnResult;
import com.nmf.site.biz.member.gen.entity.BizMember;
import com.nmf.site.biz.sms.bx.service.SmsCodeService;
import com.nmf.site.common.enums.DelFlagEnums;
import com.nmf.site.modules.sys.service.SystemService;

@Component
public class PcLoginService {
	@Autowired
	SmsCodeService smsCodeService;
	public static void login(String cpassword,String dbPassword,Integer delFlag,String telNo,ReturnResult returnResult) {
		DelFlagEnums delFlagEnums = DelFlagEnums.getType(delFlag);
		if(!SystemService.validatePassword(cpassword,dbPassword)) {
			returnResult.setStatus(RspStatus.FAILED.value);
			returnResult.setMessage("密码错误，请重新输入密码");
		}else {
		    // 加入账号禁用功能
			if (delFlagEnums.equals(BizMember.DEL_FLAG_DELETE)) {
				returnResult.setStatus(RspStatus.FAILED.value);
				returnResult.setMessage("改账号已被系统管理员禁用，如有疑问请联系系统管理员！");
			} else {
				returnResult.setData("token", MD5PawService.getMd5Psw(telNo));
			}
		}
	}
	
	
	public void loginByCode(String code,String telNo,Integer delFlag,ReturnResult returnResult) {
		DelFlagEnums delFlagEnums = DelFlagEnums.getType(delFlag);
		
		 // 加入账号禁用功能
		if (!delFlagEnums.equals(DelFlagEnums.DEL_FLAG_NORMAL)) {
			returnResult.setStatus(RspStatus.FAILED.value);
			returnResult.setMessage("改账号已被系统管理员禁用，如有疑问请联系系统管理员！");
		} else {
			if(smsCodeService.isRight(telNo, code)) {
				// 如果用户被禁用，则不能登录成功
				returnResult.setData("token", MD5PawService.getMd5Psw(telNo));
			}else {
				returnResult.setStatus(RspStatus.FAILED.value);
				returnResult.setMessage("验证码错误，请重新获取");
			}
		}
	}
}
